import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: HomeView,
    },
    {
      path: '/about',
      name: 'about',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/AboutView.vue'),
    },
    // 子应用路由
    {
      path: '/child-a',
      name: 'child-a',
      component: () => import('../views/ChildAView.vue'),
      meta: { childRoute: '/' }, // 子应用默认路由
    },
    {
      path: '/child-a/home',
      name: 'child-a-home',
      component: () => import('../views/ChildAView.vue'),
      meta: { childRoute: '/' }, // 子应用HomeView对应路由
    },
    {
      path: '/child-a/about',
      name: 'child-a-about',
      component: () => import('../views/ChildAView.vue'),
      meta: { childRoute: '/about' }, // 子应用AboutView对应路由
    },
    {
      path: '/child-b',
      name: 'child-b',
      component: () => import('../views/ChildBView.vue'),
      meta: { childRoute: '/' }, // 子应用默认路由
    },
    {
      path: '/child-b/home',
      name: 'child-b-home',
      component: () => import('../views/ChildBView.vue'),
      meta: { childRoute: '/' }, // 子应用HomeView对应路由
    },
    {
      path: '/child-b/about',
      name: 'child-b-about',
      component: () => import('../views/ChildBView.vue'),
      meta: { childRoute: '/about' }, // 子应用AboutView对应路由
    },
  ],
})

export default router
